home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / init_inet_daemon.c < prev    next >
C/C++ Source or Header  |  1994-04-13  |  2KB  |  93 lines

  1. RCS_ID_C="$Id: init_inet_daemon.c,v 1.2 1994/04/12 22:04:15 jraja Exp $";
  2. /*
  3.  * init_inet_daemon.c - obtain socket accepted by the inetd
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      :
  12.  * Last modified:
  13.  */
  14.  
  15. /****** net.lib/init_inet_daemon ****************************************
  16.  
  17.     NAME
  18.         init_inet_daemon - obtain socket accepted by the inetd
  19.  
  20.     SYNOPSIS
  21.         int init_inet_daemon(void);
  22.  
  23.     FUNCTION
  24.         Obtain the server socket accepted by the inetd, the Internet
  25.         super-server.
  26.  
  27.     RETURN VALUES
  28.         socket descriptor if successful, -1 with specific error code
  29.         on errno otherwise.
  30.  
  31.     ERRORS
  32.         ENXIO     - The process was not started by the inetd.
  33.  
  34.     NOTES
  35.         If the process was started by the inetd, but the ObtainSocket()
  36.         call fails, then this function exit()s with some specific exit
  37.         code, so that inetd can clean up the unobtained socket.
  38.  
  39.         Use the net.lib function set_socket_stdio() to redirect stdio,
  40.         stdout and stderr to the returned socket, if necessary.
  41.  
  42.     AUTHOR
  43.         Jarno Rajahalme, Pekka Pessi, 
  44.         the AmiTCP/IP Group <amitcp-group@hut.fi>,
  45.         Helsinki University of Technology, Finland.
  46.  
  47.     SEE ALSO
  48.         serveraccept(), set_socket_stdio(), bsdsocket/ObtainSocket(),
  49.         netutil/inetd
  50. *****************************************************************************
  51. *
  52. */
  53.  
  54. #include <exec/types.h>
  55. #include <dos/dosextens.h>
  56.  
  57. #include <proto/socket.h>
  58. #include <proto/exec.h>
  59.  
  60. #include <stdlib.h>
  61. #include <errno.h>
  62. #include <inetd.h>
  63.  
  64. int
  65. init_inet_daemon(void)
  66. {
  67.   struct Process *me = (struct Process *)FindTask(NULL);
  68.   struct DaemonMessage *dm = (struct DaemonMessage *)me->pr_ExitData;
  69.   int sock;
  70.  
  71.   if (dm == NULL) {
  72.     /*
  73.      * No DaemonMessage, return error code
  74.      */    
  75.     errno = ENXIO; /* "Device not configured" */
  76.     return -1;
  77.   }
  78.   
  79.   /*
  80.    * Obtain the server socket
  81.    */
  82.   sock = ObtainSocket(dm->dm_Id, dm->dm_Family, dm->dm_Type, 0);
  83.   if (sock < 0) {
  84.     /*
  85.      * If ObtainSocket fails we need to exit with this specific exit code
  86.      * so that the inetd knows to clean things up
  87.      */
  88.     exit(DERR_OBTAIN);
  89.   }
  90.  
  91.   return sock;
  92. }
  93.